<template>
  <div class="archive-browse-container">
    <div class="archive-browse">
      <h2>{{ $t('archiveBrowse') }}</h2>
      <div class="upload-container">
        <label class="upload-label" for="fileInput">
          <i class="upload-icon"></i>
          <span class="upload-text">{{ $t('uploadFile') }}</span>
        </label>
        <input
          id="fileInput"
          type="file"
          @change="handleFileChange"
          accept="image/*"
          class="file-input"
        />
      </div>
      <div class="preview-container">
        <div class="preview-box">
          <img :src="previewImage" v-if="previewImage" class="preview-image" />
          <div class="preview-placeholder" v-else>
            <i class="preview-icon"></i>
            <p class="preview-text">{{ $t('previewText') }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      previewImage: '',
    };
  },
  methods: {
    handleFileChange(event) {
      const file = event.target.files[0];
      if (file) {
        if (file.type.startsWith('image/')) {
          const reader = new FileReader();
          reader.onload = (e) => {
            this.previewImage = e.target.result;
          };
          reader.readAsDataURL(file);
        } else {
          alert(this.$t('invalidFileType'));
          this.previewImage = '';
        }
      }
    },
  },
};
</script>


<style scoped>
.archive-browse-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f5f5f5;
}

.archive-browse {
  width: 90%;
  max-width: 600px;
  background-color: #ffffff;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 30px;
}

h2 {
  text-align: center;
  color: #333333;
  margin-bottom: 30px;
  font-size: 28px;
}

.upload-container {
  display: flex;
  justify-content: center;
  margin-bottom: 30px;
}

.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border: 2px dashed #4a90e2;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.upload-label:hover {
  background-color: rgba(74, 144, 226, 0.1);
}

.upload-icon {
  font-size: 40px;
  color: #4a90e2;
  margin-bottom: 15px;
}

.upload-text {
  font-size: 16px;
  color: #4a90e2;
  text-align: center;
}

.file-input {
  position: absolute;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.preview-container {
  display: flex;
  justify-content: center;
}

.preview-box {
  width: 100%;
  height: 400px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background-color: #f9f9f9;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999999;
}

.preview-icon {
  font-size: 60px;
  margin-bottom: 20px;
}

.preview-text {
  font-size: 18px;
  text-align: center;
}
</style>